package com.hm.system.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.hm.common.common.QrCodeUtil;
import com.hm.system.util.SystemConfigDef.Api.Rest;
import com.hm.system.web.su.BaseController;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * @author shishun.wang
 * @date 2016年6月12日 上午1:05:22
 * @version 1.0
 * @describe
 */
@ResponseBody
@RestController
@RequestMapping(value = Rest.Sys.REST_SYS_QR_CODE_INFO)
public class SysQrCodeController extends BaseController {

	public static final String swaggerTag = "系统二维码管理";

	@RequestMapping(value = "/{clientTime}.png", method = RequestMethod.GET)
	@ApiOperation(value = "获取二维码", httpMethod = "GET", notes = "获取随机验证码", tags = swaggerTag)
	public void verifyCode(HttpServletRequest request, HttpServletResponse response,
			@ApiParam(required = false, name = "size", value = "二维码尺寸") @RequestParam(required = false, name = "size") Integer size,
			@ApiParam(required = true, name = "content", value = "二维码内容") @RequestParam("content") String content,
			@ApiParam(required = true, name = "clientTime", value = "时间戳") @PathVariable Long clientTime)
					throws Exception {
		{// 设置请求响应头
			response.setHeader("Pragma", "No-cache");
			response.setHeader("Cache-Control", "no-cache");
			response.setDateHeader("Expires", 0);
			response.setContentType("image/jpeg");
		}

		new QrCodeUtil().encode(size, content, response.getOutputStream());
	}
}
